{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <form class="form form-horizontal" id="form" method="post" action="{:url('update')}">
        <input type="hidden" name="id" value="{$model.id ?? ''}">
        <input type="hidden" id="imgurl" name="imgurl" value="{$model.image ?? ''}">

        <!-- 奖品图片 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>奖品图片：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <img style="width: 100px;height: 100px;" id="src_image" src="{$model.image ?? ''}" />
                <input type="file" class="input-text" placeholder="图片地址" name="image" value="{$model.image ?? ''}" onchange="file_up()">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 奖品名称 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>奖品名称：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" placeholder="奖品名称" name="name" value="{$model.name ?? ''}" datatype="*" nullmsg="请填写奖品名称">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 奖品来源	 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>奖品来源：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <select name="source" class="select" value="{$model.source ?? ''}" placeholder="奖品来源" datatype="*" nullmsg="请确认是否奖品来源">
                    <option value="1">生日好礼奖品</option>
                </select>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 奖品库存 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>奖品库存：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" placeholder="奖品库存" name="number" value="{$model.number ?? ''}" datatype="*" nullmsg="请填写奖品库存">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 奖品概率 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>奖品概率：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" placeholder="奖品概率" name="chance" value="{$model.chance ?? '显示奖品的总和为100'}" datatype="*" nullmsg="请填写奖品概率">
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 兑奖类型 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>兑奖类型：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <select name="prize_type" class="select" value="{$model.prize_type ?? ''}" placeholder="兑奖类型" datatype="*" nullmsg="请确认兑奖类型">
                    <option value="1">二维码类型</option>
                    <option value="2">会员码类型</option>
                    <option value="3">实体类</option>
                </select>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <!-- 首页显示 -->
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>是否首页显示：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <select name="isindex" class="select" value="{$model.isindex ?? ''}" placeholder="是否首页显示" datatype="*" nullmsg="请确认是否首页显示">
                    <option value="0">是</option>
                    <option value="1">否</option>
                </select>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-primary radius">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__LIB__/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="__LIB__/layui/layui.js"></script>
<script>

    $(function () {

        var $iamge = $("input[name='imgurl']").val();
        if($iamge == ""){
            $("#src_image").css("display","none");
        }

        ifid();
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form").Validform({
            tiptype: 2,
            ajaxPost: true,
            showAllError: true,
            callback: function (ret){
                ajax_progress(ret);
            }
        });
    })

    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#datetimes' //指定元素
        });
    });

    function ifid(){
        if(!($("input[name='id']").val() == "")){
            years = $("input[name='a_year']").val();
            mouths = $("input[name='a_month']").val();
            days = $("input[name='a_day']").val();
            times = years + "-" + mouths + "-" + days;
            $("#datetimes").val(times);
        }
    }

    function file_up(){
        // FormData对象，来发送二进制文件。
        var formdata = new FormData(form);

        $.ajax({
            type: "POST",
            url: '{:url(\'upload\')}',
            data:formdata,
            dataType: "json",
            processData: false,
            contentType: false,
            success: function(data){
                console.log(data);
                $("#imgurl").val(data);
            }
        });
    }
</script>
{/block}
